package com.uzai.console.web.takebal;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.common.enums.DeviceTypeEnum;
import com.uzai.console.common.utils.Tools;
import com.uzai.console.dto.takebal.redpackettemplate.*;
import com.uzai.console.service.takebal.RedPacketTemplateService;
import com.uzai.console.vo.base.SelectKeyVo;
import com.uzai.console.vo.takebal.redpackettemplate.RedPacketTemplateInfoVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liuqi
 * @date 2021年08月25日 20:15
 */
@Api(value = "发送红包",tags = "提现管理|发送红包")
@ApiSort(16)
@RestController
public class RedPacketTemplateContoller extends BaseController {
    private Logger logger = LoggerFactory.getLogger(RedPacketTemplateContoller.class);

    @Autowired
    private RedPacketTemplateService redPacketTemplateService;

    @ApiOperation(value = "查询所有红包模板列表", notes = "查询所有红包模板列表", response = RedPacketTemplateInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/redPacketTemplate/findRedPacketTemplateList")
    public Object findRedPacketTemplateList(@RequestBody RedPacketTemplateQuery redPacketTemplateQuery){
        return redPacketTemplateService.findRedPacketTemplateList(redPacketTemplateQuery);
    }

    @ApiOperation(value = "分页查询红包模板列表", notes = "分页查询红包模板列表", response = RedPacketTemplateInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/redPacketTemplate/findRedPacketTemplatePage")
    public Object findRedPacketTemplatePage(@RequestBody RedPacketTemplateQuery redPacketTemplateQuery){
        return redPacketTemplateService.findRedPacketTemplatePage(redPacketTemplateQuery);
    }

    @ApiOperation(value = "保存红包模板(已弃用)", notes = "保存红包模板(已弃用)")
    @ApiOperationSupport(order = 2)
    @PostMapping("/redPacketTemplate/updateRedPacketTemplate")
    public Object updateRedPacketTemplate(@RequestBody RedPacketTemplateUpdateDto redPacketTemplateUpdateDto ){
        redPacketTemplateService.updateRedPacketTemplateInfo(redPacketTemplateUpdateDto);
        return true;
    }

    @ApiOperation(value = "添加或修改红包模板", notes = "添加或修改红包模板")
    @ApiOperationSupport(order = 2)
    @PostMapping("/redPacketTemplate/saveRedPacketTemplate")
    public Object saveRedPacketTemplate(@RequestBody RedPacketTemplateInfoDto redPacketTemplateInfoDto ){
        redPacketTemplateService.saveRedPacketTemplate(redPacketTemplateInfoDto);
        return true;
    }

    @ApiOperation(value = "手动发送红包", notes = "手动发送红包")
    @ApiOperationSupport(order = 3)
    @PostMapping("/redPacketTemplate/sendRedPacket")
    public Object sendRedPacket(@RequestBody RedPacketSendDto redPacketSendDto){
//        if(Tools.getInteger(redPacketSendDto.getRedPackageType()).intValue() == 0){ //指定会员红包
//            redPacketTemplateService.sendRedPacket(redPacketSendDto);
//        }else{ //手气红包
//            redPacketTemplateService.sendRedPacketRandom(redPacketSendDto);
//        }

        redPacketTemplateService.batchSendRedPacket(redPacketSendDto);

        return true;
    }

    @ApiOperation(value = "会员所属端", notes = "会员所属端", response = SelectKeyVo.class)
    @ApiOperationSupport(order = 4)
    @PostMapping("/redPacketTemplate/findDeviceTypeList")
    public Object findDeviceTypeList(){
        List<SelectKeyVo> selectKeyVoList = new ArrayList<>();
        SelectKeyVo selectKeyVo_private = new SelectKeyVo();
        selectKeyVo_private.setKey(DeviceTypeEnum.DT_PC_WECHAT.getKey());
        selectKeyVo_private.setValue("个人微信");
        selectKeyVoList.add(selectKeyVo_private);

        SelectKeyVo selectKeyVo_work = new SelectKeyVo();
        selectKeyVo_work.setKey(DeviceTypeEnum.DT_WORK_WECHAT.getKey());
        selectKeyVo_work.setValue("企业微信");
        selectKeyVoList.add(selectKeyVo_work);

        SelectKeyVo selectKeyVo_pub= new SelectKeyVo();
        selectKeyVo_pub.setKey(DeviceTypeEnum.WX_PUB.getKey());
        selectKeyVo_pub.setValue("公众号");
        selectKeyVoList.add(selectKeyVo_pub);

        return selectKeyVoList;
    }

    @ApiOperation(value = "删除红包模板", notes = "删除红包模板")
    @ApiOperationSupport(order = 5)
    @PostMapping("/redPacketTemplate/deleteRedPacketTemplate")
    public Object deleteRedPacketTemplate(@RequestBody RedPacketTemplateIdDto redPacketTemplateIdDto ){
        redPacketTemplateService.deleteRedPacketTemplate(redPacketTemplateIdDto);
        return true;
    }

}
